package com.meiqiongproperty.yiguanjia.ui;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;

import com.meiqiongproperty.yiguanjia.R;

/**
 * author: Administrator
 * date: 2017/6/12.
 * package:com.meiqiongproperty.yiguanjia.ui
 */

public class SlashTextView extends TextView {

    private Context context;

    public SlashTextView(Context context) {
        super(context);
        this.context = context;
    }

    public SlashTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }


    public SlashTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(context.getResources().getColor(R.color.decription_grey_3));
        paint.setStrokeWidth(dip2px(context, 1));
        canvas.drawLine(0, dip2px(context, 5),getMeasuredWidth(), getMeasuredHeight()-dip2px(context, 5), paint);
    }

    private int dip2px(Context context,float dipValue)
    {
        Resources r = context.getResources();
        return (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    }

}
